package SentenceTranslator;
//import logging
import Include.ASMConstructor;
import Common.REG;
import Include.TACLine;
import Common.TacOperandType;
import Main.SymbolManager;
import java.util.ArrayList;
import java.util.List;
import Common.POSTYPE;


public class ParaTranslator {
    public List<String> SentenceTranslate(SymbolManager SymbolManager, TACLine TACLine) {
        List<String> asmlines = new ArrayList<>();
        if (TACLine.src1.operType == TacOperandType.IMM) {
            String src = TACLine.src1.value;
            SymbolManager.setEspBias(4);
            asmlines.add(ASMConstructor.construct_asm("push", src));
        } else if (TACLine.src1.operType == TacOperandType.VAR) {
            String str_src1 = SymbolManager.encodeVar(TACLine.src1.value);
            POSTYPE pos = SymbolManager.position(str_src1);
            if (pos == POSTYPE.REG) {
                REG reg_src1 = SymbolManager.avalueReg(str_src1);
                SymbolManager.pushReg(reg_src1, 0);
                asmlines.add(ASMConstructor.construct_asm("push", reg_src1));
            } else if (pos == POSTYPE.MEM) {
                int mem_src1 = SymbolManager.avalueMem(str_src1);
                asmlines.add(ASMConstructor.construct_asm("mov", REG.EDI, mem_src1));
                SymbolManager.pushReg(REG.EDI, 0);
                asmlines.add(ASMConstructor.construct_asm("push", REG.EDI));
            } else if (pos == POSTYPE.GLOBAL) {
                String src = TACLine.src1.value;
                asmlines.add(ASMConstructor.construct_asm("mov", REG.EDI, src));
                SymbolManager.pushReg(REG.EDI, 0);
                asmlines.add(ASMConstructor.construct_asm("push", REG.EDI));
            } else {
                System.out.println("para default error");
            }
        }
        return asmlines;
    }
}
